<?php
namespace app\common\controller;
use app\common\controller\Auth;
use think\Controller;
use think\Session;
use think\Request;

class Common extends Controller
{
	/*@要搜索的关键字*/
	protected $keyword_search = [];
	/*@模型对象*/
	protected $model = null;
	/*@每页条数*/
	protected $row = 1;
	/*@排序条件*/
	protected $order = '';
	/*@執行失敗 
	* true失敗
	* 用来判断是否执行后置
	*/
	protected $error = false;
	/*
	* 日志数据
	* 操作数据id
	*/
	protected $log_id = '';
	/**
	* 日志操作
	* 操作转态 可不设置
	*/
	protected $log_ty = '';
	/*@后置方法*/
	protected $afterActionList = [];

	/**
     * 引入后台控制器的traits
     */
    use \app\common\library\traits\Backend;
    use \app\common\library\traits\Log;

    /**
    *tp封装构造函数
    */
    protected function _initialize()
    {
        parent::_initialize();
		
		/*判断权限*/
		$request = Request::instance();
		$module = strtolower($request->module());
		$controller = strtolower($request->controller());
		$action = strtolower($request->action());
		/*判断是否登录*/
		if(!Session::get('admin.admin_id'))
		{
            if($module . $controller . $action == 'indexindexindex')
            {
                $this->redirect(url('login/login/login'));
            }else{
                throwError(config('state.STATUS_CODE_FOURTWO'),config('state.STATUS_MSG_FOURTWO'));
            }
        }
		/*免权限控制*/
		if(!in_array('/' . $module . '/' . $controller . '/' . $action,config('overall.FUN_AUTH')))
		{
			if(!(new Auth())->is_auth(Session::get('admin.admin_id'),'/' . $module . '/' . $controller . '/' . $action))
			{
				throwError(config('state.STATUS_CODE_FIVE'),config('state.STATUS_MSG_FIVE'));
			}
		}
    }
    /**
    *过滤前端获取到的参数
    *$info 被过滤的-二维数组,并且前端传递undefeated转化为空字符串
    */
    protected function params($info)
    {
    	$params = array();
	    foreach ($info as $key => $value) 
	    {
	        if(!is_array($value))
	        {
	            $params[$key] = strip_tags(htmlspecialchars(trim($value),ENT_QUOTES));
	        }else{
	            foreach ($value as $k => $v) 
	            {
	                $params[$key][$k] = strip_tags(htmlspecialchars(trim($v),ENT_QUOTES));
	            }
	        }
	    }
	    return $params;
    }
}
